package com.jerry.template.module.mainpage.shouye.jinghua.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jerry.template.R;
import com.jerry.template.base.BaseApplication;
import com.jerry.template.base.BaseViewHolder;
import com.jerry.template.base.MyBaseAdapter;
import com.jerry.template.module.mainpage.shouye.jinghua.activity.JinghuaWebViewActivity;
import com.jerry.template.module.mainpage.shouye.jinghua.entity.Jhentity;
import com.jerry.template.module.mainpage.shouye.jinghua.entity.JinghuaEntity;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 16-5-16.
 */
public class jinghuaListViewAdapter<T> extends MyBaseAdapter<T>{
    private List<T> list;
    private JinghuaViewHolder viewHolder;
    private ImageLoader imageLoader;
    private DisplayImageOptions options;
    private Context context;
    private Jhentity.DataBean entity;

    public jinghuaListViewAdapter(Context context, List list) {
        super(context, list);
        this.list=list;
        this.context=context;
        imageLoader = BaseApplication.getApplication().getImageLoader();
        options = BaseApplication.getApplication().getImageOptions();
    }


    @Override
    public int getLayoutId() {
        return R.layout.jinghua_list_item;
    }

    @Override
    public BaseViewHolder getViewHolder() {
        return new JinghuaViewHolder();
    }

    @Override
    public void bindViews(View view, BaseViewHolder viewHolder) {
        entity = (Jhentity.DataBean) getItem(((JinghuaViewHolder)viewHolder).position);
        if(entity !=null){
            imageLoader.displayImage(entity.getImage_url(),((JinghuaViewHolder)viewHolder).img,options);
            ((JinghuaViewHolder)viewHolder).title.setText(entity.getTitle());
            ((JinghuaViewHolder)viewHolder).time.setText(entity.getDatetime());
        }


    }

     class JinghuaViewHolder extends BaseViewHolder implements View.OnClickListener{
        @BindView(R.id.img)
        public ImageView img;

        @BindView(R.id.title)
        public TextView title;

        @BindView(R.id.time)
        public TextView time;



        @Override
        @OnClick({R.id.img,R.id.title,R.id.time})
        public void onClick(View v) {
            Intent i =  new Intent();
            i.setClass(context, JinghuaWebViewActivity.class);
            i.putExtra("webUrl",((Jhentity.DataBean)getItem(position)).getSource_url());
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);
        }
    }
}
